package org.hmh.offer;

/**
 * Created this one by HMH on 2018/1/21.
 */
public class t29 {

    static public class Solution {
        public int GetNumberOfK(int [] array , int k) {
            int left = 0;
            int right = array.length - 1;

            int up = 0, bottom = 0;
            while(left <= right){
                int mid = left + (right-left)/2;
                if(array[mid] > k){
                    right = mid - 1;
                }else{
                    left = mid + 1;
                }
            }
            bottom = right;

            left = 0;
            right = array.length - 1;
            while(left <= right){
                int mid = left + (right-left)/2;
                if(array[mid] < k){
                    left = mid + 1;
                }else{
                    right = mid - 1;
                }

            }
            up = left;
            return bottom - up + 1;

        }
    }

    public static void main(String[] args){
        Solution solution = new Solution();
        int result = solution.GetNumberOfK(new int[]{1, 2, 3, 3, 3, 3, 4, 5}, 3);
        System.out.println(result);

    }

}
